package export.pet
{
	import base.*;
	
	import com.dusk.util.ResUtil;
	import com.game.data.vo.PetDataVO;
	
	import export.bullet.*;
	
	import flash.display.*;
	import flash.geom.*;
	
	public class PetMonkey3 extends BasePet
	{
		
		public function PetMonkey3(param1:BaseHero, param2:PetDataVO)
		{
			super(param1, param2);
			this.horizonSpeed = 5;
			this.attackBackInfoDict["hit1"] = {
				"hitMaxCount"    : 99,
				"attackBackSpeed": [6, -5],
				"attackInterval" : 999,
				"power"          : 12,
				"attackKind"     : "physics"
			};
			this.attackBackInfoDict["hit2"] = {
				"hitMaxCount"    : 99,
				"attackBackSpeed": [-15, 0],
				"attackInterval" : 24,
				"power"          : 12,
				"attackKind"     : "physics",
				"addEffect"      : [{
					"name": BaseAddEffect.FIRE,
					"time": 7,
					"hurt": Number(this.getAtk()) / 10
				}]
			};
			this.attackBackInfoDict["hit3"] = {
				"hitMaxCount"    : 99,
				"attackBackSpeed": [-10, 0],
				"attackInterval" : 24,
				"power"          : 12,
				"attackKind"     : "magic"
			};
			this.attackBackInfoDict["hit4"] = {
				"hitMaxCount"    : 99,
				"attackBackSpeed": [-10, 0],
				"attackInterval" : 24,
				"power"          : 12,
				"attackKind"     : "magic"
			};
			this.setAction("idle");
			this.skillCD1 = [gc.frameClips * 4, gc.frameClips * 8];
			this.skillCD2 = [gc.frameClips * 4, gc.frameClips * 10];
			this.skillCD3 = [gc.frameClips * 4, gc.frameClips * 15];
		}
		
		private var skill3Release:Boolean = false;
		
		override protected function initBBDC():void
		{
			var _loc1_:* = null;
			var _loc2_:Array = BaseBitmapDataPool.getBitmapDataArrayByName("PetMonkeyBmd3");
			if (_loc2_)
			{
				_loc1_ = {
					"name"  : "body",
					"source": _loc2_
				};
				bbdc = new BaseBitmapDataClip([_loc1_], 150, 150, new Point(0, 0));
				bbdc.setOffsetXY(-8, 5);
				bbdc.setFrameStopCount([[2, 2, 2, 3, 2, 4], [4, 4, 4, 4], [8], [2, 2, 2, 2, 10], [2, 2, 8], [2, 9, 15], [10], [1, 1]]);
				bbdc.setFrameCount([6, 4, 1, 5, 3, 3, 1, 20]);
				bbdc.setEnterFrameCallBack(this.enterFrameFunc, this.exitFrameFunc);
				bbdc.setAddScriptWhenFrameOver(this.scriptFrameOverFunc);
				this.bodyContainer.addChild(bbdc);
				return;
			}
			throw new Error("PetMonkey3--BitmapData Error!");
		}
		
		override protected function initCollideArea():void
		{
			this.colipse = ResUtil.getNewObj("ObjectBaseSprite") as Sprite;
			this.colipse.visible = false;
			this.addChild(this.colipse);
		}
		
		override public function setAction(param1:String):void
		{
			super.setAction(param1);
			var _loc2_:Point = this.bbdc.getCurPoint();
			switch (param1)
			{
				case "idle":
					if (_loc2_.y != 0)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(0);
					}
					this.bbdc.setState(param1);
					break;
				case "walk":
					if (_loc2_.y != 1)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(1);
					}
					this.bbdc.setState(param1);
					break;
				case "hurt":
					if (_loc2_.y != 2)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(2);
					}
					this.bbdc.setState(param1);
					break;
				case "hit1":
					if (_loc2_.y != 4)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(4);
					}
					this.bbdc.setState(param1);
					break;
				case "hit2":
					if (_loc2_.y != 5)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(5);
					}
					this.bbdc.setState(param1);
					break;
				case "hit3":
					if (_loc2_.y != 6)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(6);
					}
					this.bbdc.setState(param1);
					break;
				case "hit4":
					if (_loc2_.y != 7)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(7);
					}
					this.bbdc.setState(param1);
					break;
				case "dead":
					if (_loc2_.y != 3)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(3);
					}
					this.bbdc.setState(param1);
			}
		}
		
		override protected function scriptFrameOverFunc(param1:int):void
		{
			var _loc2_:String = this.bbdc.getState();
			switch (_loc2_)
			{
				case "walk":
					this.bbdc.setFramePointX(0);
					break;
				case "idle":
					this.bbdc.setFramePointX(0);
					break;
				case "hit1":
					this.setAction("idle");
					break;
				case "hit2":
					this.setAction("idle");
					break;
				case "hit3":
					this.setAction("idle");
					break;
				case "hit4":
					this.setAction("idle");
					break;
				case "hurt":
					this.setStatic();
					this.setAction("idle");
					break;
				case "dead":
					this.destroy();
			}
		}
		
		override protected function enterFrameFunc(param1:Point):void
		{
			var _loc2_:String = this.bbdc.getState();
			var _loc3_:uint = this.getBBDC().getDirect();
			var _loc4_:Point = new Point();
			switch (_loc2_)
			{
				case "hit1":
					if (gc.isSingleGame() || gc.sid == this.sourceRole.sid)
					{
						if (param1.x == 2)
						{
							if (this.bbdc.getCurFrameCount() == 8)
							{
								if (_loc3_ == 0)
								{
									_loc4_.x = this.x - 100;
								}
								else
								{
									_loc4_.x = this.x + 100;
								}
								_loc4_.y = this.y - 40;
								this.doHit1(_loc3_, _loc4_);
								break;
							}
							break;
						}
						break;
					}
					break;
				case "hit2":
					if (gc.isSingleGame() || gc.sid == this.sourceRole.sid)
					{
						if (param1.x == 0)
						{
							if (this.bbdc.getCurFrameCount() == 2)
							{
								if (_loc3_ == 0)
								{
									_loc4_.x = this.x - 35;
								}
								else
								{
									_loc4_.x = this.x + 35;
								}
								_loc4_.y = this.y - 60;
								this.doHit2(_loc3_, _loc4_);
								break;
							}
							break;
						}
						break;
					}
					break;
				case "hit3":
					if (gc.isSingleGame() || gc.sid == this.sourceRole.sid)
					{
						if (param1.x == 0)
						{
							if (this.bbdc.getCurFrameCount() == 10)
							{
								if (_loc3_ == 0)
								{
									_loc4_.x = this.x - 45;
								}
								else
								{
									_loc4_.x = this.x + 45;
								}
								_loc4_.y = this.y - 50;
								this.doHit3(_loc3_, _loc4_);
								break;
							}
							break;
						}
						break;
					}
					break;
				case "hit4":
					if (gc.isSingleGame() || gc.sid == this.sourceRole.sid)
					{
						if (param1.x == 0)
						{
							if (this.bbdc.getCurFrameCount() == 1)
							{
								if (_loc3_ == 0)
								{
									_loc4_.x = this.x;
								}
								else
								{
									_loc4_.x = this.x;
								}
								_loc4_.y = this.y - 15;
								this.doHit4_1(_loc3_, _loc4_);
								if (_loc3_ == 0)
								{
									_loc4_.x = this.x - 10;
								}
								else
								{
									_loc4_.x = this.x + 10;
								}
								_loc4_.y = this.y - 15;
								this.doHit4_2(_loc3_, _loc4_);
								break;
							}
							break;
						}
						break;
					}
			}
		}
		
		override protected function beforeSkill3Start():Boolean
		{
			return this.getMp() >= this._petInfo.findPetUsedMagic("lj") && Boolean(this.skill3Release) && Boolean(this._petInfo.findHasStudySkill("lj"));
		}
		
		override protected function beforeSkill1Start():Boolean
		{
			return this.getMp() >= this._petInfo.findPetUsedMagic("lyq") && AUtils.GetDisBetweenTwoObj(this, this.curAttackTarget) <= 400 && Boolean(this._petInfo.findHasStudySkill("lyq"));
		}
		
		override protected function beforeSkill2Start():Boolean
		{
			return this.getMp() >= this._petInfo.findPetUsedMagic("xj") && Boolean(this._petInfo.findHasStudySkill("xj"));
		}
		
		override public function reduceHp(param1:int, param2:Boolean = false):void
		{
			super.reduceHp(param1, param2);
			this.skill3Release = true;
		}
		
		override protected function releSkill1():void
		{
			
			this.faceToTarget();
			this.setAction("hit2");
			this.lastHit = "hit2";
			_petInfo.reduceMp(_petInfo.findPetUsedMagic("lyq"))
		}
		
		override protected function releSkill2():void
		{
			
			this.faceToTarget();
			this.setAction("hit3");
			this.lastHit = "hit3";
			_petInfo.reduceMp(_petInfo.findPetUsedMagic("xj"))
		}
		
		override protected function releSkill3():void
		{
			
			this.faceToTarget();
			this.setAction("hit4");
			this.lastHit = "hit4";
			_petInfo.reduceMp(_petInfo.findPetUsedMagic("lj"))
		}
		
		override protected function normalHit():void
		{
			
			this.setAction("hit1");
			this.lastHit = "hit1";
			this.faceToTarget();
		}
		
		override public function getRealPower(param1:String, param2:Boolean = true):int
		{
			var _loc3_:* = null;
			var _loc4_:uint = this.getCriteValue(param2) ? 2 : 1;
			var _loc5_:uint = this.getMagicAddValue();
			var _loc6_:Number = this.isGXP ? 1.2 : Number(1);
			switch (param1)
			{
				case "hit1":
					return (this.getAtk() + _loc5_) * _loc4_ * _loc6_;
				case "hit2":
					_loc3_ = this._petInfo.getPetHarmObj("lyq");
					if (_loc3_)
					{
						return (_loc3_.first + _loc5_) * _loc4_ * _loc6_;
					}
					return 0;
					break;
				case "hit3":
					_loc3_ = this._petInfo.getPetHarmObj("xj");
					if (_loc3_)
					{
						return Number(_loc3_.first) * _loc6_;
					}
					return 0;
					break;
				case "hit4":
					_loc3_ = this._petInfo.getPetHarmObj("lj");
					if (_loc3_)
					{
						return (_loc3_.first + _loc5_) * _loc4_ * _loc6_;
					}
					return 0;
					break;
				default:
					return 0;
			}
		}
		
		override protected function exitFrameFunc(param1:Point):void
		{
		}
		
		override protected function myIntelligence():void
		{
			if (!this.isBeAttacking())
			{
				super.myIntelligence();
			}
		}
		
		override public function isAttacking():Boolean
		{
			return this.curAction == "hit1" || this.curAction == "hit2" || this.curAction == "hit3" || this.curAction == "hit4";
		}
		
		override protected function isCannotMoveWhenAttackOnFloor():Boolean
		{
			return this.curAction == "hit1" || this.curAction == "hit2" || this.curAction == "hit3";
		}
		
		private function doHit1(param1:uint, param2:Point):void
		{
			var _loc3_:SpecialEffectBullet = new SpecialEffectBullet("PetMonkey3Bullet1");
			_loc3_.x = param2.x;
			_loc3_.y = param2.y;
			_loc3_.setOwner(this);
			_loc3_.setDirect(param1);
			_loc3_.setAction("hit1");
			gc.gameScene.addChild(_loc3_);
			this.magicBulletArray.push(_loc3_);
		}
		
		private function doHit2(param1:uint, param2:Point):void
		{
			var _loc3_:SpecialEffectBullet = new SpecialEffectBullet("PetMonkey3Bullet2");
			_loc3_.x = param2.x;
			_loc3_.y = param2.y;
			_loc3_.setOwner(this);
			_loc3_.setDirect(param1);
			_loc3_.setAction("hit2");
			gc.gameScene.addChild(_loc3_);
			this.magicBulletArray.push(_loc3_);
		}
		
		private function doHit4_1(param1:uint, param2:Point):void
		{
			var _loc3_:FollowTargetBullet = new FollowTargetBullet("PetMonkey3Bullet3_1");
			_loc3_.x = param2.x;
			_loc3_.y = param2.y;
			_loc3_.setOwner(this);
			_loc3_.setDisable();
			_loc3_.setDirect(param1);
			_loc3_.setAction("hit4");
			var _loc4_:int = gc.gameScene.getChildIndex(this);
			gc.gameScene.addChildAt(_loc3_, _loc4_);
			this.magicBulletArray.push(_loc3_);
		}
		
		private function doHit4_2(param1:uint, param2:Point):void
		{
			var _loc3_:FollowTargetBullet = new FollowTargetBullet("PetMonkey3Bullet3_2");
			_loc3_.x = param2.x;
			_loc3_.y = param2.y;
			_loc3_.setOwner(this);
			_loc3_.setDirect(param1);
			_loc3_.setAction("hit4");
			gc.gameScene.addChild(_loc3_);
			this.magicBulletArray.push(_loc3_);
		}
		
		private function doHit3(param1:uint, param2:Point):void
		{
			var _loc3_:FollowTargetBullet = new FollowTargetBullet("PetMonkey1Bullet2");
			_loc3_.x = param2.x;
			_loc3_.y = param2.y;
			_loc3_.setOwner(this);
			_loc3_.setIsDestroyWhenLastFrame(false);
			_loc3_.setIsDestroyWhenOwnerHurt(false);
			_loc3_.setDestroyInCount(gc.frameClips * 4);
			_loc3_.setDirect(param1);
			_loc3_.setAction("hit3");
			gc.gameScene.addChild(_loc3_);
			this.magicBulletArray.push(_loc3_);
			this.skill3Release = false;
		}
	}
}
